package com.hyhy.hycloud.commons.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author daihuihui
 * @date 2018/11/7
 */
@AllArgsConstructor
public enum Sex {
    /**
     *
     */
    MALE("M", "男", 1),
    FEMALE("F", "女", 2),
    OTHER("O", "其他", 3),
    UNKNOWN("U", "未知", 4);

    @Getter
    private String code;

    @Getter
    private String cn;

    @Getter
    private Integer value;

    public static Sex parse(String s) {
        for (Sex sex : Sex.values()) {
            if (sex.name().equalsIgnoreCase(s) || sex.getCode().equalsIgnoreCase(s) || sex.getCn().equals(s)) {
                return sex;
            }
        }
        throw new UnsupportedOperationException();
    }

    public static Sex valueOf(Integer value) {
        switch (value) {
            case 1:
                return MALE;
            case 2:
                return FEMALE;
            case 3:
                return OTHER;
            case 4:
                return UNKNOWN;
            default:
                throw new UnsupportedOperationException();
        }
    }
}

